﻿#region codejockey.net Copyright Banner

/***************************************************************\
 * Copyright 2010 codejockey.net.                                *
 *                                                               *
 * This code is property of codejockey.net and cannot be used    *
 * without explicit permission given by a codejockey.net         *
 * Representative.  For details contact: source@codejockey.net   *
 \***************************************************************/

#endregion

#region Using Clause

using System;

using codejockey.BingPaper.Utils;
using codejockey.BingPaper.Utils.ReplacementTokens;

using Microsoft.VisualStudio.TestTools.UnitTesting;

#endregion

namespace codejockey.BingPaper.UnitTests
{
  /// <summary>
  /// Summary description for TokenTests
  /// </summary>
  [TestClass]
  public class TokenTests
  {
    #region Additional test attributes

    //
    // You can use the following additional attributes as you write your tests:
    //
    // Use ClassInitialize to run code before running the first test in the class
    // [ClassInitialize()]
    // public static void MyClassInitialize(TestContext testContext) { }
    //
    // Use ClassCleanup to run code after all tests in a class have run
    // [ClassCleanup()]
    // public static void MyClassCleanup() { }
    //
    // Use TestInitialize to run code before running each test 
    // [TestInitialize()]
    // public void MyTestInitialize() { }
    //
    // Use TestCleanup to run code after each test has run
    // [TestCleanup()]
    // public void MyTestCleanup() { }
    //

    #endregion

    [TestInitialize]
    public void InitTest()
    {
      if (TokenManager.Tokens.Count == 0)
        TokenManager.LoadTokens();

      var token = new CountryCodeReplacementToken();

      if (!TokenManager.Tokens.ContainsKey(token.Token))
        TokenManager.Tokens.Add(token.Token, token);
    }

    [TestMethod]
    public void TestCurrentUserToken()
    {
      string expected = Environment.UserName;
      string actual = TokenManager.Parse("$currentuser$");

      Assert.AreEqual(expected, actual);
    }

    [TestMethod]
    public void TestCurrentMinuteToken()
    {
      string expected = DateTime.Now.ToString("mm");
      string actual = TokenManager.Parse("$minute$");

      Assert.AreEqual(expected, actual);
    }

    [TestMethod]
    public void TestCurrentDomainToken()
    {
      string expected = Environment.UserDomainName;
      string actual = TokenManager.Parse("$currentdomain$");

      Assert.AreEqual(expected, actual);
    }

    [TestMethod]
    public void TestCurrentYearToken()
    {
      string expected = DateTime.Now.ToString("yyyy");
      string actual = TokenManager.Parse("$year$");

      Assert.AreEqual(expected, actual);
    }

    [TestMethod]
    public void TestCurrentDayToken()
    {
      string expected = DateTime.Now.ToString("dd");
      string actual = TokenManager.Parse("$day$");

      Assert.AreEqual(expected, actual);
    }

    [TestMethod]
    public void TestCurrentMonthToken()
    {
      string expected = DateTime.Now.ToString("MM");
      string actual = TokenManager.Parse("$month$");

      Assert.AreEqual(expected, actual);
    }

    [TestMethod]
    public void TestCountryCodeReplacementTokenDescription()
    {
      var token = new CountryCodeReplacementToken();
      string expected = token.Description;
      string actual = TokenManager.Tokens[token.Token].Description;

      Assert.AreEqual(expected, actual,
                      string.Format("Values did not match.  Expected: {0} Actual: {1}.", expected, actual));
    }
  }
}